﻿//#pragma execution_character_set("GB2312")

#ifndef MAINDEMOWINDOW_H
#define MAINDEMOWINDOW_H

#include <QMainWindow>
#include <QMap>
#include <QCloseEvent>
#include  "config.h"
#include "playerwidget.h"
#include "localcapture.hpp"
#include "limathread.h"
#include "GlobalHeader.h"


class MainDemoWindow : public QMainWindow
{
    friend class limaThread;
    Q_OBJECT

public:
    MainDemoWindow(QWidget *parent = nullptr);
    ~MainDemoWindow();

    void OnGotMyVideoFrame(uint32_t w,uint32_t h,const char *y, size_t y_size,
                                 const char *u, size_t u_size,
                                 const char *v, size_t v_size,
                                 uint64_t timestamp);

    void OnGotUserVideoFrame(const char * uid,uint32_t w,uint32_t h,const char *y, size_t y_size,
                             const char *u, size_t u_size,
                             const char *v, size_t v_size,
                             uint64_t timestamp);


    void OnGotUserAudioFrame(const char * uid,const char *pcm,
                                             uint32_t bitsPerSample,
                                             uint32_t sampleRate,
                                             uint32_t numberOfChannels,
                                             int64_t numberofFrames,
                                             int64_t timestamp);



    void OnEngineTypeChanged();

    QString  getEnginTypeDescStr() const ;
    QString  getPeerid() const ;






    static void widgetCenter(QWidget *pWidget,QWidget*parent = nullptr);
    static void showHintLabel(QWidget *parent,QString strText,QString strFontSize = "32px",QString strColor = "#ffffff",QString strBgColor = "#000000"); //一个提示便签  会淡化消失

signals:
    void    Sig_ShowMessage(const QString  & strContent);



private:
    QString CheckPlayerWidget(PlayerWidget * player);

protected:
    //这是一个虚函数，继承自QEvent.只要重写了这个虚函数，当你按下窗口右上角的"×"时，就会调用你所重写的此函数.
    void closeEvent(QCloseEvent*event);
    void resizeEvent(QResizeEvent *event);

private slots:
    void On_NewUser(const QString uid);
    void On_UserLeaved(const QString uid);
    void On_LabelClicked();
    void On_SendMessage();
    void On_ShowMessage(const QString & msg);

public:
    Ui::MainWindow *                            ui;
    limaThread *                                _thrlima;
    QMap<QString,PlayerWidget*>                  _userMap;
    QMutex                                      _userMapMutex;
    std::atomic<bool>                           _isclosed;
};
#endif // MAINDEMOWINDOW_H
